package com.set.hashset;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

class Empl{
	public String fname;
	public String lname;
	public Empl(String fname, String lname){
		this.fname = fname;
		this.lname = lname;
		System.out.println("empl()");
	}
	public boolean equals(Object obj){
		System.out.println("equals");
		Empl e = (Empl)obj;
		return this.fname==e.fname&&this.lname==e.lname;
	}
	public int hashcode(){
		System.out.println("hashcode()");
		int hash = fname.hashCode();
		hash = hash+ lname.hashCode();
		return hash;
	}
	@Override
	public String toString() {
		return fname + "," + lname;
	}
}
public class SetExmple {
	public static void main(String[] args) {
		Set set = new HashSet();
		Set<Empl> set1 = Collections.synchronizedSet(set);
		set1.add(new Empl("Hare","ram"));
		set1.add(new Empl("Raghu","Raj"));
		set1.add(new Empl("Hare","ram"));
		System.out.println(set);
		System.out.println(set.size());
		
		Set set2 = new HashSet();
		set2.add(1);
		set2.add(1);
		set2.add(2);
		System.out.println(set2);
		System.out.println(set2.size());
		set1.add(new Empl("deepak", "kumar"));
	}
}
